package com.guguskins.back.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.guguskins.back.entity.GuContractRate;
import com.guguskins.back.entity.vo.ResultVo;
import com.guguskins.back.service.GuContractRateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @date 2021/6/4 13:35
 */
@RestController
@RequestMapping("/contractRate")
public class GuContractRateController {

    @Autowired
    private GuContractRateService contractRateService;

    @GetMapping("/rate")
    public ResultVo getRate() {
        GuContractRate contractRate = contractRateService.getOne(new LambdaQueryWrapper<GuContractRate>() {
            {
                select(GuContractRate::getGoodsTotalMaxRate, GuContractRate::getGoodsTotalMinRate);
                eq(GuContractRate::getId, 1);
            }
        });
        return ResultVo.success(contractRate);
    }

    @GetMapping("/back/detail")
    public ResultVo backDetail() {
        GuContractRate contractRate = contractRateService.getById(1);
        return ResultVo.success(contractRate);
    }

    @PostMapping("/back/edit")
    public ResultVo backEdit(@RequestBody GuContractRate contractRate) {
        boolean update = contractRateService.update(contractRate, new LambdaUpdateWrapper<GuContractRate>() {
            {
                eq(GuContractRate::getId, 1);
            }
        });
        if (update) {
            return ResultVo.success("修改成功");
        }
        return ResultVo.fail("修改失败");
    }

}
